             //
    //  ReadyDiSignle.m
    //  ZYShang
    //
    //  Created by wangguangming on 15/7/29.
    //  Copyright © 2015年 Amber. All rights reserved.
    //

#import "ReadyDiSignle.h"
#import "Base.h"
#import "Targets.h"
#import "Delivery.h"
#import "School.h"
#import "UserModel.h"
#import "AFNetworking.h"
#import "BuMen.h"
#import "MD5Encode.h"

static ReadyDiSignle *signle=nil;
@implementation ReadyDiSignle
+(ReadyDiSignle *)signle
{
    if (signle==nil)
        {
        signle=[[ReadyDiSignle alloc] init];
        }
    return  signle;
    
}
-(void)readyDisWorking//配好
{
    NSString *string=[NSString stringWithFormat:@"%@/api/zls/orders/trace/picked",URL];
        // 1.创建请求
    NSURL *url = [NSURL URLWithString:string];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    request.HTTPMethod = @"PUT";
    
        // 2.设置请求头
    [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    
        // 3.设置请求体
       
    NSData *data=[self.oidString dataUsingEncoding:NSUTF8StringEncoding];
    request.HTTPBody = data;
    
        // 4.发送请求
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError)
     {
     if (connectionError!=nil)
         {
         return ;
         
         }

    [[NSNotificationCenter defaultCenter] postNotificationName:@"do" object:self];
     
    }];
}
-(void)readyDisWorking:(NSString *)sender//缺货配好
{
    NSString *string=[NSString stringWithFormat:@"%@/api/zls/orders/trace/picked?quants=%@",URL,sender];
        // 1.创建请求
    NSURL *url = [NSURL URLWithString:string];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    request.HTTPMethod = @"PUT";
    
        // 2.设置请求头
    [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    
        // 3.设置请求体
    
    NSData *data=[self.oidString dataUsingEncoding:NSUTF8StringEncoding];
    request.HTTPBody = data;
    
        // 4.发送请求
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError)
     {
     if (connectionError!=nil)
         {
         return ;
         
         }

     [[NSNotificationCenter defaultCenter] postNotificationName:@"do" object:self];
     
     }];

}
-(void)getRdItemWorking
{
        ///api/zls/orders/ones/picked
    NSString *urlString=[NSString stringWithFormat:@"%@/api/zls/orders/ones/picked?start=0&count=1000",URL];
    NSURL *url=[NSURL URLWithString:urlString];
    NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:url];
    [request setHTTPShouldHandleCookies:YES];
    
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *respose,NSData *data,NSError *error){
        if (error!=nil)
            {
            return ;
            
            }

        NSDictionary *dict= [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; 
            // NSLog(@"%@",dict);
       
        NSMutableArray *array1=[NSMutableArray array];
        for (NSDictionary *d in dict[@"targets"])
            {
             Targets *targets=[[Targets alloc] init];
            [targets setValuesForKeysWithDictionary:d];
            [array1 addObject:targets];
           }
        self.tatgetsArray=[NSMutableArray arrayWithArray:array1];
    }];
}
-(void)getRdItemWorkingFrom:(int )from To:(int)to//分页已配好订单
{
        ///api/zls/orders/ones/picked
    NSString *urlString=[NSString stringWithFormat:@"%@/api/zls/orders/ones/picked?start=%d&count=%d",URL,from,to];
    NSURL *url=[NSURL URLWithString:urlString];
    NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:url];
    [request setHTTPShouldHandleCookies:YES];
    
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *respose,NSData *data,NSError *error){
        if (error!=nil)
            {
            return ;
            
            }
        NSDictionary *dict= [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; 
            // NSLog(@"%@",dict);
        
        NSMutableArray *array1=[NSMutableArray array];
        for (NSDictionary *d in dict[@"targets"])
            {
            Targets *targets=[[Targets alloc] init];
            [targets setValuesForKeysWithDictionary:d];
            [array1 addObject:targets];
            }
        self.tatgetsArray=[NSMutableArray arrayWithArray:array1];
    }];
 
}
-(void)getRdItemWorking:(NSString *)idstring//个人已配好货订单
{
        ///api/zls/orders/ones/picked
    NSString *urlString=[NSString stringWithFormat:@"%@/api/zls/orders/ones/picked?uid=%@&start=0&count=1000",URL,idstring];
    NSURL *url=[NSURL URLWithString:urlString];
    NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:url];
    [request setHTTPShouldHandleCookies:YES];
    
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *respose,NSData *data,NSError *error){
        if (error!=nil)
            {
            return ;
            
            }
        NSDictionary *dict= [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; 
            //  NSLog(@"%@",respose);
        
        NSMutableArray *array1=[NSMutableArray array];
        for (NSDictionary *d in dict[@"targets"])
            {
            Targets *targets=[[Targets alloc] init];
            [targets setValuesForKeysWithDictionary:d];
            [array1 addObject:targets];
            }
        self.tatgetsArray=[NSMutableArray arrayWithArray:array1];
    }];

}
-(void)getCancelWorking
{
        ///api/zls/orders/ones/picked
    NSString *urlString=[NSString stringWithFormat:@"%@/api/zls/orders/ones/canceled?start=0&count=1000",URL];
    NSURL *url=[NSURL URLWithString:urlString];
    NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:url];
    [request setHTTPShouldHandleCookies:YES];
    
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *respose,NSData *data,NSError *error){
        if (error!=nil)
            {
            return ;
            
            }
        NSDictionary *dict= [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; 
            // NSLog(@"%@",dict);
        
       
        NSMutableArray *array1=[NSMutableArray array];
        for (NSDictionary *d in dict[@"targets"])
            {
            Targets *targets=[[Targets alloc] init];
            [targets setValuesForKeysWithDictionary:d];
            [array1 addObject:targets];
            }
        self.cancelArray=[NSMutableArray arrayWithArray:array1];
    }];
}
-(void)getNotSaveworking
{
    NSString *urlString=[NSString stringWithFormat:@"%@/api/zls/orders/ones/problem/notcompleted?start=0&count=1000",URL];
    NSURL *url=[NSURL URLWithString:urlString];
    NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:url];
    [request setHTTPShouldHandleCookies:YES];
    
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *respose,NSData *data,NSError *error){
        if (error!=nil)
            {
            return ;
            
            }
        NSDictionary *dict= [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; 
            // NSLog(@"%@",dict);
        
        
        NSMutableArray *array1=[NSMutableArray array];
        for (NSDictionary *d in dict[@"targets"])
            {
            Targets *targets=[[Targets alloc] init];
            [targets setValuesForKeysWithDictionary:d];
            [array1 addObject:targets];
            }
        self.notSaveArray=[NSMutableArray arrayWithArray:array1];
    }];

}
-(void)getSaveworking
{
    NSString *urlString=[NSString stringWithFormat:@"%@/api/zls/orders/ones/problem/completed?start=0&count=1000",URL];
    NSURL *url=[NSURL URLWithString:urlString];
    NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:url];
    [request setHTTPShouldHandleCookies:YES];
    
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *respose,NSData *data,NSError *error){
        if (error!=nil)
            {
            return ;
            
            }
        NSDictionary *dict= [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; 
            //  NSLog(@"%@",dict);
        
        
        NSMutableArray *array1=[NSMutableArray array];
        for (NSDictionary *d in dict[@"targets"])
            {
            Targets *targets=[[Targets alloc] init];
            [targets setValuesForKeysWithDictionary:d];
            [array1 addObject:targets];
            }
        self.saveArray=[NSMutableArray arrayWithArray:array1];
    }];
 
}
-(void)getSendworking// 已发货记录 管理员获取所有Delivery记录
{
    NSString *urlString=[NSString stringWithFormat:@"%@/api/zls/orders/deliveries?start=0&count=1000",URL];
    NSURL *url=[NSURL URLWithString:urlString];
    NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:url];
    [request setHTTPShouldHandleCookies:YES];
    
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *respose,NSData *data,NSError *error){
        if (error!=nil)
            {
            return ;
            
            }
        NSDictionary *dict= [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; 
        
        NSMutableArray *array=[NSMutableArray array];
        for (NSDictionary *d in dict[@"targets"])
            {
            Delivery *delivery=[[Delivery alloc] init];
            [delivery setValuesForKeysWithDictionary:d];
           
            [array addObject:delivery];      
            }
        self.DeliveryArray=[NSMutableArray arrayWithArray:array];
    }];

}
-(void)getSendworkingFrom:(int )from To:(int )to//分页发货记录
{
    
    NSString *urlString=[NSString stringWithFormat:@"%@/api/zls/orders/deliveries?start=%d&count=%d",URL,from,to];
    NSURL *url=[NSURL URLWithString:urlString];
    NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:url];
    [request setHTTPShouldHandleCookies:YES];
    
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *respose,NSData *data,NSError *error){
        if (error!=nil)
            {
            return ;
            
            }
        NSDictionary *dict= [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; 
        
        NSMutableArray *array=[NSMutableArray array];
        for (NSDictionary *d in dict[@"targets"])
            {
            Delivery *delivery=[[Delivery alloc] init];
            [delivery setValuesForKeysWithDictionary:d];
            
            [array addObject:delivery];      
            }
        self.DeliveryArray=[NSMutableArray arrayWithArray:array];
    }];

}
-(void)getNeedSendworking
{
            NSString *urlString=[NSString stringWithFormat:@"%@/api/zls/orders/ones/tosent?from=s&start=0&count=1000",URL];
            NSURL *url=[NSURL URLWithString:urlString];
            NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:url];
            [request setHTTPShouldHandleCookies:YES];
            
            [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *respose,NSData *data,NSError *error){
                if (error!=nil)
                    {
                    return ;
                    
                    }
                NSDictionary *dict= [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; 
                NSLog(@"%@",dict);
                NSMutableArray *array1=[NSMutableArray array];
                for (NSDictionary *d in dict[@"targets"])
                    {
                    Targets *targets=[[Targets alloc] init];
                    [targets setValuesForKeysWithDictionary:d];
                    [array1 addObject:targets];
                    }
                self.needSendArray=[NSMutableArray arrayWithArray:array1];
            }];

}
-(void)yudingNeedSendworking{
    NSString *urlString=[NSString stringWithFormat:@"%@/api/zls/orders/ones/tosentByBook?from=s&start=0&count=1000",URL];
    NSURL *url=[NSURL URLWithString:urlString];
    NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:url];
    [request setHTTPShouldHandleCookies:YES];
    
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *respose,NSData *data,NSError *error){
        if (error!=nil)
            {
            return ;
            
            }
        NSDictionary *dict= [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; 
        NSLog(@"dict==%@",dict);
        NSMutableArray *array1=[NSMutableArray array];
        for (NSDictionary *d in dict[@"targets"])
            {
            NSLog(@"%@",d);
            Targets *targets=[[Targets alloc] init];
            
            [targets setValuesForKeysWithDictionary:d];
            [array1 addObject:targets];
            }
        self.yudingneedSendArray=[NSMutableArray arrayWithArray:array1];
    }];

}
-(void)sendWorking
{
    NSString *string=[NSString stringWithFormat:@"%@/api/zls/orders/trace/sent?oid=%@",URL,self.oidString];
        // 1.创建请求
    NSURL *url = [NSURL URLWithString:string];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    request.HTTPMethod = @"PUT";
    
        // 2.设置请求头
    [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    
     
        // 4.发送请求
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError)
     {
     if (connectionError!=nil)
         {
         return ;
         
         }
         // NSLog(@"%@",response);
     [[NSNotificationCenter defaultCenter] postNotificationName:@"do" object:self];
     }];

}
-(void)searchWorking
{
    NSString *urlString=[NSString stringWithFormat:@"%@/api/zls/orders/search?id=%@&start=0&count=1000",URL,self.oidString];
    NSURL *url=[NSURL URLWithString:urlString];
    NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:url];
    [request setHTTPShouldHandleCookies:YES];
    
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *respose,NSData *data,NSError *error){
        if (error!=nil)
            {
            return ;
            
            }
        NSMutableArray *array=[NSMutableArray array];
        NSDictionary *dict= [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; 
        for (NSDictionary *d in dict[@"targets"]) 
            {
            Targets *targets=[[Targets alloc] init];
            [targets setValuesForKeysWithDictionary:d];
            [array addObject:targets];
            }
        self.searchArray=[NSMutableArray arrayWithArray:array];
          }];
 
}
-(void)getAllwokers
{
    NSString *urlString=[NSString stringWithFormat:@"%@/api/zls/users/mkt?mktId=%@&start=0&count=1000",URL,self.oidString];
    NSURL *url=[NSURL URLWithString:urlString];
    NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:url];
    [request setHTTPShouldHandleCookies:YES];
    
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *respose,NSData *data,NSError *error){
        if (error!=nil)
            {
            return ;
            
            }
        NSMutableArray *array=[NSMutableArray array];
        NSDictionary *dict= [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; 
        for (NSDictionary *d in dict[@"targets"])
            {
            UserModel *user=[[UserModel alloc] init];
            [user setValuesForKeysWithDictionary:d];
            [array addObject:user];
            }
        self.workerArray=[NSMutableArray arrayWithArray:array];
        [[NSNotificationCenter defaultCenter] postNotificationName:@"do" object:self];
    }];

}
-(void)changePassWord:(NSString *)old for:(NSString *)newp;
{
    NSString *string=[NSString stringWithFormat:@"%@/api/zls/users/%@/pwd?oldpwd=%@&newpwd=%@",URL,self.oidString,[MD5Encode md5:old],[MD5Encode md5:newp]];
        // 1.创建请求
    NSURL *url = [NSURL URLWithString:string];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    request.HTTPMethod = @"PUT";
    
        // 2.设置请求头
    [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    
        // 3.设置请求体

    
      
        // 4.发送请求
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError)
     {
     if (connectionError!=nil)
         {
         return ;
         
         }
         // NSLog(@"%@",response);
     NSDictionary *dict= [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; 
         // NSLog(@"%@",dict);
     }];

}
-(void)setPassWord:(NSString *)account
{
    NSString *string=[NSString stringWithFormat:@"%@/api/zls/users/resetpwd?account=%@",URL,account];
        // 1.创建请求
    NSURL *url = [NSURL URLWithString:string];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    request.HTTPMethod = @"PUT";
    
//         2.设置请求头
    [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    
        // 3.设置请求体
    
        // 4.发送请求
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError)
     {
     if (connectionError!=nil)
         {
         return ;
         
         }
         // NSLog(@"%@ %@ %@",response,data,connectionError);
     }];
 }
-(void)Refuseaccept//直接拒收
{
    NSString *string=[NSString stringWithFormat:@"%@/api/zls/orders/trace/rejected?oid=%@",URL,self.oidString];
        // 1.创建请求
    NSURL *url = [NSURL URLWithString:string];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    request.HTTPMethod = @"PUT";
    
        // 2.设置请求头
    [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    
        // 3.设置请求体
    
//    NSData *data=[self.oidString dataUsingEncoding:NSUTF8StringEncoding];
//    request.HTTPBody = data;
    
        // 4.发送请求
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError)
     {
     if (connectionError!=nil)
         {
         return ;
         
         }
         // NSLog(@"%@",response);
     [[NSNotificationCenter defaultCenter] postNotificationName:@"do" object:self];
     
     }];

}
-(void)Refuseaccepts:(NSString *)string//缺货拒收
{
    NSString *urlstring=[NSString stringWithFormat:@"%@/api/zls/orders/trace/closed?quants=%@",URL,string];
        // 1.创建请求
    NSURL *url = [NSURL URLWithString:urlstring];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    request.HTTPMethod = @"PUT";
    
        // 2.设置请求头
    [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    
        // 3.设置请求体
    
    NSData *data=[self.oidString dataUsingEncoding:NSUTF8StringEncoding];
    request.HTTPBody = data;
    
        // 4.发送请求
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError)
     {
     if (connectionError!=nil)
         {
         return ;
         
         }
         // NSLog(@"%@",response);
     [[NSNotificationCenter defaultCenter] postNotificationName:@"do" object:self];
     
     }];

}
-(void)accept//确认收货
{
    NSString *string=[NSString stringWithFormat:@"%@/api/zls/orders/trace/received",URL];
        // 1.创建请求
    NSURL *url = [NSURL URLWithString:string];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    request.HTTPMethod = @"PUT";
    
        // 2.设置请求头
    [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    
        // 3.设置请求体
    
            NSData *data=[self.oidString dataUsingEncoding:NSUTF8StringEncoding];
            request.HTTPBody = data;
    
        // 4.发送请求
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError)
     {
     if (connectionError!=nil)
         {
         return ;
         
         }
         // NSLog(@"%@,%@",response,data);
     [[NSNotificationCenter defaultCenter] postNotificationName:@"do" object:self];
     
     }];

}
-(void)nobody//失联
{
    NSString *string=[NSString stringWithFormat:@"%@/api/zls/orders/trace/nobody?oid=%@",URL,self.oidString];
        // 1.创建请求
    NSURL *url = [NSURL URLWithString:string];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    request.HTTPMethod = @"PUT";
    
        // 2.设置请求头
    [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    
        // 3.设置请求体
    
        //    NSData *data=[self.oidString dataUsingEncoding:NSUTF8StringEncoding];
        //    request.HTTPBody = data;
    
        // 4.发送请求
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError)
     {
     if (connectionError!=nil)
         {
         return ;
         
         }
         // NSLog(@"%@",response);
     [[NSNotificationCenter defaultCenter] postNotificationName:@"do" object:self];
     
     }];
 
}
-(void)writeQusetItem:(NSString *)string//记录问题单
{
    
    NSString *urlstring=[NSString stringWithFormat:@"%@/api/zls/orders/trace/problem?oid=%@&note=%@",URL,self.oidString,[self.noteString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
        // 1.创建请求
    NSURL *url = [NSURL URLWithString:urlstring];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    request.HTTPMethod = @"PUT";
   
        // 2.设置请求头
    [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    
        // 3.设置请求体
    
    NSData *data=[string dataUsingEncoding:NSUTF8StringEncoding];
    request.HTTPBody = data;
    
        // 4.发送请求
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError)
     {
     if (connectionError!=nil)
         {
         return ;
         
         }
         //  NSLog(@"%@",data);
     
     NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
         // NSLog(@"dict= %@",dict);
     
     NSString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
         // NSLog(@"string=%@",string);
     
     [[NSNotificationCenter defaultCenter] postNotificationName:@"do" object:self];
     
     }];

}
-(void)getnoDeliveryWorking//获取未完成的包裹
{
    NSString *urlString=[NSString stringWithFormat:@"%@/api/zls/orders/deliveries/notcompleted?start=0&count=1000",URL];
    NSURL *url=[NSURL URLWithString:urlString];
    NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:url];
    [request setHTTPShouldHandleCookies:YES];
    
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *respose,NSData *data,NSError *error){
        if (error!=nil)
            {
            return ;
            
            }
        NSDictionary *dict= [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; 
        
        NSMutableArray *array=[NSMutableArray array];
        for (NSDictionary *d in dict[@"targets"])
            {
            Delivery *delivery=[[Delivery alloc] init];
            [delivery setValuesForKeysWithDictionary:d];
            
            [array addObject:delivery];      
            }
        self.NodeliveArray=[NSMutableArray arrayWithArray:array];
    }];

}

-(void)onwork//上班
{
    NSString *urlString=[NSString stringWithFormat:@"%@/api/zls/users/checkin?uids=%@",URL,self.oidString];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString]];
    request.HTTPMethod = @"POST";
         
        // 2.设置请求头
         [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
        
       // 3.设置请求体
       // NSDictionary *json = [NSDictionary dictionaryWithObject:self.oidString forKey:@"uids"];;
        
    //    NSData --> NSDictionary
     // NSDictionary --> NSData
//    NSData *data =[self.oidString dataUsingEncoding:NSUTF8StringEncoding];

        // request.HTTPBody = data;
        
       // 4.发送请求
        [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
            if (connectionError!=nil)
                {
                return ;
                
                }
            NSDictionary *dict= [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; 
                //  NSLog(@"%@",dict[@"msg"]);
            
             [[NSNotificationCenter defaultCenter] postNotificationName:@"do" object:self];  
            }]; 
}
-(void)offwork//下班
{
    NSString *urlString=[NSString stringWithFormat:@"%@/api/zls/users/checkout?uids=%@",URL,self.oidString];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString]];
    request.HTTPMethod = @"POST";
    
        // 2.设置请求头
    [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    
        // 3.设置请求体
        // NSDictionary *json = [NSDictionary dictionaryWithObject:self.oidString forKey:@"uids"];;
    
        //    NSData --> NSDictionary
        // NSDictionary --> NSData
        //    NSData *data =[self.oidString dataUsingEncoding:NSUTF8StringEncoding];
    
        // request.HTTPBody = data;
    
        // 4.发送请求
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
        if (connectionError!=nil)
            {
            return ;
            
            }
         NSDictionary *dict= [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; 
        
            //  NSLog(@"%@ ",dict[@"msg"]);
        if (dict!=nil)
            {
            self.noticeArray=[NSMutableArray arrayWithObject:dict];
           }
        else
            {
            
            }
        [[NSNotificationCenter defaultCenter] postNotificationName:@"do" object:self];  
    }]; 

}
-(void)getAllCitys//获取所以省份
{
    NSString *urlString=[NSString stringWithFormat:@"%@/api/schools/hasmkt/group",URL];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString]];
    request.HTTPMethod = @"GET";
    
        // 2.设置请求头
    [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    
             // 4.发送请求
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
        if (connectionError!=nil)
            {
            return ;
            
            }
       NSDictionary *dict= [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];  
        self.cityArray=[NSMutableArray arrayWithArray:[dict allKeys]];
    }]; 

}
-(void)getallSchool//获取学校
{
    NSString *urlString=[NSString stringWithFormat:@"%@/api/schools/hasmkt/%@",URL,self.oidString ];
    NSString *string=[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:string]];
    request.HTTPMethod = @"GET";
    
        // 2.设置请求头
    [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    
        // 4.发送请求
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
        if (connectionError!=nil)
            {
            return ;
            
            }
       NSDictionary *dict= [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; 
       
        NSMutableArray *array=[NSMutableArray array];
        for (NSDictionary *d in dict[@"targets"])
            {
            School *school=[[School alloc] init];
            [school setValuesForKeysWithDictionary:d];
            [array addObject:school];
           }
        self.schoolArray=[NSMutableArray arrayWithArray:array];
    }]; 

}
-(void)dongjieWorking//冻结员工账号
{
    NSString *urlString=[NSString stringWithFormat:@"%@/api/zls/users/unable?uid=%@",URL,self.oidString];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString]];
    request.HTTPMethod = @"POST";
    
        // 2.设置请求头
    [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    
        // 3.设置请求体
        // NSDictionary *json = [NSDictionary dictionaryWithObject:self.oidString forKey:@"uids"];;
    
        //    NSData --> NSDictionary
        // NSDictionary --> NSData
        //    NSData *data =[self.oidString dataUsingEncoding:NSUTF8StringEncoding];
    
        // request.HTTPBody = data;
    
        // 4.发送请求
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
        if (connectionError!=nil)
            {
            return ;
            
            }
            // NSLog(@"%@ %@ %@",response,data,connectionError);
        [[NSNotificationCenter defaultCenter] postNotificationName:@"do" object:self];  
    }]; 
    
       

}

-(void)jiedongWorking//解冻员工账号
{
    NSString *urlString=[NSString stringWithFormat:@"%@/api/zls/users/enable?uid=%@",URL,self.oidString];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString]];
    request.HTTPMethod = @"POST";
    
        // 2.设置请求头
    [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    
        // 3.设置请求体
        // NSDictionary *json = [NSDictionary dictionaryWithObject:self.oidString forKey:@"uids"];;
    
        //    NSData --> NSDictionary
        // NSDictionary --> NSData
        //    NSData *data =[self.oidString dataUsingEncoding:NSUTF8StringEncoding];
    
        // request.HTTPBody = data;
    
        // 4.发送请求
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
        if (connectionError!=nil)
            {
            return ;
            
            }
            // NSLog(@"%@ %@ %@",response,data,connectionError);
        [[NSNotificationCenter defaultCenter] postNotificationName:@"do" object:self];  
    }]; 
    
     

}
-(void)lizhiWorking//员工离职
{
    NSString *urlString=[NSString stringWithFormat:@"%@/api/zls/users/%@",URL,self.oidString];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString]];
    request.HTTPMethod = @"DELETE";
    
        // 2.设置请求头
    [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    
           [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
               if (connectionError!=nil)
                   {
                   return ;
                   
                   }
                   // NSLog(@"%@ %@ %@",response,data,connectionError);
        [[NSNotificationCenter defaultCenter] postNotificationName:@"do" object:self];  
    }]; 
    

}
-(void)chaxunWorker//查询员工
{
    NSString *urlString=[NSString stringWithFormat:@"%@/api/zls/users/search?account=%@",URL,self.oidString];
//    NSString *urlString=[NSString stringWithFormat:@"http://192.168.1.188/api/zls/users/search?account=000000"];
    
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString]];
       
        // 2.设置请求头
    [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
        if (connectionError!=nil)
            {
            return ;
            
            }
         NSDictionary *dict= [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; 
        
        UserModel *user=[[UserModel alloc] init];
        [user setValuesForKeysWithDictionary:dict];
        
        self.workerItem=[NSMutableArray arrayWithObject:user];
        [[NSNotificationCenter defaultCenter] postNotificationName:@"do" object:self];  
    }]; 
    

}
-(void)bumenliebiao//部门列表
{
    NSString *urlString=[NSString stringWithFormat:@"%@/api/zls/departments",URL];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString]];
    
        // 2.设置请求头
    [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
        if (connectionError!=nil)
            {
            return ;
            
            }
        NSDictionary *dict= [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; 
        NSMutableArray *array=[NSMutableArray array];
        for (NSDictionary *d in dict[@"targets"]) 
            {
            BuMen *bumen=[[BuMen alloc] init];
            [bumen setValuesForKeysWithDictionary:d];
            [array addObject:bumen];
            }
        self.bumenArray=[NSMutableArray arrayWithArray:array];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"do" object:self];  
    }]; 

}
-(void)allSchool//全国学校
{
    NSString *urlString=[NSString stringWithFormat:@"%@/api/schools/hasmkt",URL];
    NSString *string=[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:string]];
    request.HTTPMethod = @"GET";
    
        // 2.设置请求头
    [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    
        // 4.发送请求
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
        if (connectionError!=nil)
            {
            return ;
            
            }
        NSDictionary *dict= [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; 
        
        NSMutableArray *array=[NSMutableArray array];
        for (NSDictionary *d in dict[@"targets"])
            {
            School *school=[[School alloc] init];
            [school setValuesForKeysWithDictionary:d];
            [array addObject:school];
            }
        self.schoolArray=[NSMutableArray arrayWithArray:array];
    }]; 

}
-(void)addWork:(NSDictionary *)dict//添加员工
{
    
    NSError *error;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error: &error];
        
    NSString *urlString=[NSString stringWithFormat:@"%@/api/zls/users",URL];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString]];
    request.HTTPMethod = @"POST";

        // 2.设置请求头
    [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
     
//    NSLog(@"%@",string);
//    NSData *data =[string dataUsingEncoding:NSUTF8StringEncoding];

    request.HTTPBody = jsonData;
    
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
        if (connectionError!=nil)
            {
            return ;
            
            }
         [[NSNotificationCenter defaultCenter] postNotificationName:@"do" object:self];
            // NSLog(@"response==%@,data==%@,connectionError==%@",response,data,connectionError);
        NSString *datdstring = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
            // NSLog(@"dataString=%@",datdstring);
         NSDictionary *dict= [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; 
            // NSLog(@"%@",dict);
    }]; 
  
}
-(void)allWorkers//获取所以员工
{
    NSString *urlString=[NSString stringWithFormat:@"%@/api/zls/users?start=0&count=1000",URL];
    NSURL *url=[NSURL URLWithString:urlString];
    NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:url];
    [request setHTTPShouldHandleCookies:YES];
    
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *respose,NSData *data,NSError *error){
        if (error!=nil)
            {
            return ;
            
            }
        NSMutableArray *array=[NSMutableArray array];
        NSDictionary *dict= [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; 
        for (NSDictionary *d in dict[@"targets"])
            {
            UserModel *user=[[UserModel alloc] init];
            [user setValuesForKeysWithDictionary:d];
            [array addObject:user];
            }
        self.workerArray=[NSMutableArray arrayWithArray:array];
        [[NSNotificationCenter defaultCenter] postNotificationName:@"do" object:self];
    }];
    

}
-(void)searchallMktid:(NSString *)mktidString Uid:(NSString *)uidString From:(long double)bengintime to:(long double)endtime//查询所有发货
{
    NSString *urlString=[NSString stringWithFormat:@"%@/api/zls/orders/count/data?from=%.0f&to=%.0f",URL,bengintime,endtime];
    if (mktidString!=nil)
        {
      urlString=[urlString stringByAppendingString:[NSString stringWithFormat:@"&mktId=%@",mktidString]];
       }
    if (uidString!=nil)
        {
        urlString=[urlString stringByAppendingString:[NSString stringWithFormat:@"&uid=%@",uidString]];
        }
        // NSLog(@"%@",urlString);
    NSURL *url=[NSURL URLWithString:urlString];
    NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:url];
    [request setHTTPShouldHandleCookies:YES];
    
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *respose,NSData *data,NSError *error){
        if (error!=nil)
            {
            return ;
            
            }
            // NSLog(@"%@,%@,%@",respose,data,error);
        NSDictionary *dict= [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; 
        self.resultDict=[NSMutableDictionary dictionaryWithDictionary:dict];        
    }];

}
-(void)setItem:(NSString *)oidString toworkId:(NSString *)workid//分配给
{
    NSString *string=[NSString stringWithFormat:@"%@/api/zls/orders/trace/problem/reasign?oid=%@&uid=%@",URL,oidString,workid];
        // 1.创建请求
    NSURL *url = [NSURL URLWithString:string];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    request.HTTPMethod = @"PUT";
    
        // 2.设置请求头
    [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    
        // 3.设置请求体
    
        //    NSData *data=[self.oidString dataUsingEncoding:NSUTF8StringEncoding];
        //    request.HTTPBody = data;
    
        // 4.发送请求
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError)
     {
     if (connectionError!=nil)
         {
         return ;
         
         }
         // NSLog(@"%@",response);
     [[NSNotificationCenter defaultCenter] postNotificationName:@"do" object:self];
     
     }];

}
-(void)changeWork:(NSDictionary *)dict//修改员工
{
    NSError *error;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error: &error];
    
    NSString *urlString=[NSString stringWithFormat:@"%@/api/zls/users/%@",URL,self.oidString];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString]];
    request.HTTPMethod = @"PUT";
    
        // 2.设置请求头
    [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    
        //    NSLog(@"%@",string);
        //    NSData *data =[string dataUsingEncoding:NSUTF8StringEncoding];
    
    request.HTTPBody = jsonData;
    
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
        if (connectionError!=nil)
            {
            return ;
            
            }
            //   NSLog(@"response==%@,data==%@,connectionError==%@",response,data,connectionError);
        NSString *datdstring = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
            //  NSLog(@"dataString=%@",datdstring);
        NSDictionary *dict= [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; 
            //  NSLog(@"%@",dict);
    }]; 

}

@end
